#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 2e5 + 10;

int n,m,Q;
int X[N << 1],Y[N << 1];

struct DSU {
	int fa[N << 1];
	void reset() { for(int i = 0;i <= 2 * n;i++) fa[i] = i; }
	int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
}S;
	
struct Graph {
	struct edge { int u,v,w; } e[N << 1];
	vec G[N << 1]; int dfn[N << 1],R[N << 1],ind[N],tim,ndn,fa[21][N << 1],val[N << 1];
	void dfs(int x) {
		if(x <= n) ind[dfn[x] = ++tim] = x,val[x] = x; else dfn[x] = tim + 1;
		for(auto y : G[x]) dfs(y); R[x] = tim;
	}
	void build(int tp) {
		ndn = n; tim = 0;
		for(int i = 1;i <= m;i++) { e[i].u = X[i],e[i].v = Y[i]; e[i].w = tp ? - min(e[i].u,e[i].v) : max(e[i].u,e[i].v); }
		sort(e + 1,e + m + 1,[](edge a,edge b) { return a.w < b.w; }); S.reset();
		for(int i = 1;i <= m;i++) {
			int u = e[i].u,v = e[i].v; u = S.gf(u); v = S.gf(v); if(u == v) continue; ++ndn; val[ndn] = abs(e[i].w);
			fa[0][u] = ndn; fa[0][v] = ndn; S.fa[u] = ndn; S.fa[v] = ndn; G[ndn].pb(u); G[ndn].pb(v);
		}
		for(int i = 1;i <= 20;i++)
			for(int j = 1;j <= ndn;j++) fa[i][j] = fa[i - 1][fa[i - 1][j]];
		dfs(ndn);
	}
	int getlow(int lim,int x) {
		for(int i = 20;i >= 0;i--) if(fa[i][x] && val[fa[i][x]] >= lim) x = fa[i][x];
		return x;
	}
	int getupp(int lim,int x) {
		for(int i = 20;i >= 0;i--) if(fa[i][x] && val[fa[i][x]] <= lim) x = fa[i][x];
		return x;
	}
}T1,T2;

namespace st {
	int ch[N << 5][2],val[N << 5],rt[N],nodenum;
	void upd(int &x,int y,int pos,int l = 1,int r = n) {
		x = ++nodenum; ch[x][0] = ch[y][0]; ch[x][1] = ch[y][1]; val[x] = val[y] + 1; if(l == r) return; int mid = l + r >> 1;
		if(pos <= mid) upd(ch[x][0],ch[y][0],pos,l,mid); else upd(ch[x][1],ch[y][1],pos,mid + 1,r);
	}
	int query(int x,int y,int xl,int xr,int l = 1,int r = n) {
		if(!y) return 0; if(xl == l && xr == r) return val[y] - val[x]; int mid = l + r >> 1;
		if(xr <= mid) return query(ch[x][0],ch[y][0],xl,xr,l,mid); else if(xl > mid) return query(ch[x][1],ch[y][1],xl,xr,mid + 1,r);
		else return query(ch[x][0],ch[y][0],xl,mid,l,mid) + query(ch[x][1],ch[y][1],mid + 1,xr,mid + 1,r);
	}
}
	
int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;Q = in; for(int i = 1;i <= m;i++) X[i] = in + 1,Y[i] = in + 1;
	T1.build(1); T2.build(0); for(int i = 1;i <= n;i++) st :: upd(st :: rt[i],st :: rt[i - 1],T1.dfn[T2.ind[i]]);
	while(Q--) {
		int s = in + 1,t = in + 1,L = in + 1,R = in + 1;
		L = T1.getlow(L,s),R = T2.getupp(R,t);
		printf("%d\n",st :: query(st :: rt[T2.dfn[R] - 1],st :: rt[T2.R[R]],T1.dfn[L],T1.R[L]) > 0);
	}
	return 0;
}
